package com.pro.springbootshop.controller;

import com.pro.springbootshop.entityExtend.OrderReturn;
import com.pro.springbootshop.entityExtend.SearchOrder;
import com.pro.springbootshop.service.OrdersService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
public class OrderController {
    @Autowired
    OrdersService ordersService;
    @ApiOperation("获取订单")
    @GetMapping("/api/order/{page}/{limit}")
    public OrderReturn getOrderList(@PathVariable(name = "page") Integer page, @PathVariable(name = "limit") Integer limit, HttpServletRequest request){
        String token = request.getHeader("token");
        return ordersService.getOrderList(page,limit,token);
    }
    @ApiOperation("买家取消订单")
    @PostMapping("/api/order/{orderId}")
    public String deleteOrder(@PathVariable(name = "orderId") Integer orderId){
        return ordersService.deleteOrder(orderId);
    }
    @ApiOperation("提交购物车中选中商品到订单")
    @GetMapping("/api/order/cart/{address}/{payment}")
    public String insertOrder(@PathVariable(name = "address") String address,@PathVariable(name = "payment") Integer payment,HttpServletRequest request){
        String token = request.getHeader("token");
        return ordersService.insertOrder(address,token,payment);
    }
    @ApiOperation("管理员获取订单")
    @PostMapping("/api/seller/order")
    public OrderReturn sellerGetOrderList(@RequestBody SearchOrder searchOrder){
        return ordersService.sellerGetOrderList(searchOrder);
    }
    @ApiOperation("管理员推进订单状态")
    @PostMapping("/api/seller/order/orderState/{orderId}")
    public String sellerUpdateOrderState(@PathVariable(name="orderId") Integer orderId){
        return ordersService.sellerUpdateOrderState(orderId);
    }
    @ApiOperation("管理员推进订单状态并提交配送方式")
    @PostMapping("/api/seller/order/orderState/{orderId}/{distribution}")
    public String sellerUpdateOrderStateAndDistribution(@PathVariable(name="orderId") Integer orderId,@PathVariable(name="distribution") String distribution){
        return ordersService.sellerUpdateOrderStateAndDistribution(orderId,distribution);
    }
    @ApiOperation("管理员取消订单")
    @PostMapping("/api/seller/order/{orderId}")
    public String sellerDeleteOrder(@PathVariable(name = "orderId") Integer orderId){
        return ordersService.sellerDeleteOrder(orderId);
    }
}
